﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ADAuthentication.Framework
{
    public class ADAuthenticationProvider : IAuthenticationProvider
    {
        #region Ctor

        public ADAuthenticationProvider(string adPath)
        {
            ADPath = adPath;
        }

        #endregion

        #region Properties

        public string ADPath
        {
            get;
            protected set;
        }

        #endregion

        #region  Implement IAuthenticationProvider interface

        public bool IsAuthenticated(string userFullName, string password)
        {
            string[] userInfo = userFullName.Split("\\".ToArray());
            if (userInfo.Length != 2)
            {
                throw new InvalidOperationException( String.Format("The UserName:{0} should include domain information, such as:CTXUS\\Admin").ToString());
            }

            return ActiveDirectoryHelper.IsAutheticated(ADPath, userInfo[0], userInfo[1], password);
        }

        #endregion
    }
}
